package com.qfedu.dao.impl;

import com.qfedu.dao.Debit_cardDao;
import com.qfedu.pojo.Cards;
import com.qfedu.pojo.Debit_card;

import java.math.BigDecimal;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Debit_cardDaoImpl extends BaseDao implements Debit_cardDao {

    @Override
    public Debit_card queryDebit_cardByCardnumber(String cardnumber) {
        String sql = "select * from debit_card where cardnumber = ?";
        return queryForOne(Debit_card.class, sql,cardnumber);
    }

    @Override
    public int currentToFixed(Debit_card debit_card, Date date,BigDecimal money,BigDecimal fixed_money, Connection connection) {
        String sql="update debit_card set money=? ,fixed_money=?,savedate=now() where cardnumber=?";
        return update(connection,sql,money,fixed_money,debit_card.getCardnumber());
    }

    @Override
    public int fixedToCurrent(Debit_card debit_card, Date date,BigDecimal money, BigDecimal fixed_money,Connection connection) {
        String sql="update debit_card set money=? ,fixed_money=?,drawdate=now() where cardnumber=?";
        return update(connection,sql,money,fixed_money,debit_card.getCardnumber());
    }

    @Override
    public int updateTime(String cardnumber, String time) {
        String sql = "update debit_card set time=? where cardnumber = ?";
        int i = update(sql,time,cardnumber);
        return i;
    }
}
